<?php

namespace app\common\model\Depot\Storage;

use app\common\model\Depot\Supplier;
use think\Model;
use traits\model\SoftDelete;

class Storage extends Model
{
    use SoftDelete;
    // 表名
    protected $name = 'depot_storage';
    // 忽略数据表不存在的字段
    protected $field = true;
    // 设置返回的结果类型
    protected $resultSetType = 'collection';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    //禁止写入时间字段
    protected $updateTime = false;
    // 软删除的字段
    protected $deleteTime = 'deletetime';
    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'supplier'
    ];
    
    public function supplier()
    {
        return $this->belongsTo(Supplier::class,'supplierid','id',[],'left')->setEagerlyType(0);
    }
    
    public function getTypeList()
    {
        return ['1' => __('Direct'), '2' => __('Back')];
    }

    public function getStatusList()
    {
        return ['0' => __('ApprovalPending'), '1' => __('Failure'), '2' => __('StockPending'), '3' => __('Completed')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
}
